#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
   connect(& exit, SIGNAL (clicked()), this, SLOT (close()));
   connect(& dir, SIGNAL (clicked()), this, SLOT (dirr()));
   connect (& box, SIGNAL (currentIndexChanged(QString)), this, SLOT (view()));
   connect(& save, SIGNAL (clicked()), this, SLOT (resave()));
}

MainWindow::~MainWindow()
{
}
 void MainWindow::dirr()
    {
        str = QFileDialog::getExistingDirectory(this, "Open Directory");
        QDir folder(str);
        QStringList filters;
        filters << "*.txt";
        list=folder.entryList(filters);
        box.addItems(list);
    }
 void MainWindow::view()
 {
     QFile read(str+char(92)+box.currentText());
     QString text;
     if(read.open(QIODevice::ReadOnly))
     {
         QTextStream out(&read);
         text = out.readAll();
     }
     qtab.setText(text);
 }

 void MainWindow::resave()
 {
     QFile write;
     write.setFileName(str+char(92)+box.currentText());
     write.open(QIODevice::WriteOnly);
     QTextStream in;
     in.setDevice(&write);
     in << qtab.toPlainText();
     write.close();
 }

